package com.jg.poiet.excel.po;

import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.util.ArrayList;
import java.util.List;

public class ISheet {

    private String name;
    private List<IRow> rowList = new ArrayList<>();
    private int maxCellNums = 0;

    public ISheet(XSSFWorkbook workbook, XSSFSheet sheet) {
        this.name = sheet.getSheetName();
        for (int i = 0; i <= sheet.getLastRowNum(); i++) {
            XSSFRow row = sheet.getRow(i);
            if (row != null) {
                maxCellNums = Math.max(maxCellNums, row.getLastCellNum());
            }
            rowList.add(new IRow(workbook, sheet, row));
        }
    }

    public ISheet(HSSFWorkbook workbook, HSSFSheet sheet) {
        this.name = sheet.getSheetName();
        for (int i = 0; i <= sheet.getLastRowNum(); i++) {
            HSSFRow row = sheet.getRow(i);
            if (row != null) {
                maxCellNums = Math.max(maxCellNums, row.getLastCellNum());
            }
            rowList.add(new IRow(workbook, sheet, row));
        }
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public List<IRow> getRowList() {
        return rowList;
    }

    public void setRowList(List<IRow> rowList) {
        this.rowList = rowList;
    }

    public int getMaxCellNums() {
        return maxCellNums;
    }

    public void setMaxCellNums(int maxCellNums) {
        this.maxCellNums = maxCellNums;
    }
}
